//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <bsp.h>
#include <init.h>
#include "timer.h"

#define PIT_LATCH   \
    ((uint16_t)((PIT_ClockRate + krn.uTickRate / 2) / krn.uTickRate))

EXTERN_C DECL_CODEINIT void CDECL InitPIT()
{
    Outl(_LOAD2, PIT_LATCH);

    Outl(_CONTROL2, Inl(_CONTROL2) | _ENABLE | _MODE | _CLKSEL);
}

EXTERN_C void CDECL BspReloadPIT()
{
}

EXTERN_C uint_t CDECL BspGetPITTime()
{
    uint16_t u16Count = Inl(_VALUE2);

    return (PIT_LATCH - 1 - u16Count) * PIT_ClockCycle;
}
